package com.test.deencredit.view_deencredit.process_widget_deencredit;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.test.deencredit.R;
import com.test.deencredit.base_deencredit.BaseProcessWidgetManager_deencredit;
import com.test.deencredit.bean_deencredit.process_deencredit.ProcessInfo_Data_deencredit;
import com.test.deencredit.dialog_deencredit.AddressSelectDialog_Tanzan_deencredit;
import com.test.deencredit.util_deencredit.http_deencredit.HttpUtil_deencredit;


public class AddressPickViewManager_Tanzan_deencredit extends BaseProcessWidgetManager_deencredit {

    private TextView titleTv_deencredit;
    private TextView inputTv_deencredit;
    private View clickView_deencredit;

    private String state_deencredit, city_deencredit;

    public AddressPickViewManager_Tanzan_deencredit(View view, ProcessInfo_Data_deencredit data, String page){
        super(view,data,page);
    }

    @Override
    protected void init_deencredit(){

        titleTv_deencredit = mView_deencredit.findViewById(R.id.vps_tv_title);
        inputTv_deencredit = mView_deencredit.findViewById(R.id.vps_tv_input);
        clickView_deencredit = mView_deencredit.findViewById(R.id.vps_view_click);

        setTitle_deencredit(mData_deencredit.getTitle_deencredit());
        inputTv_deencredit.setHint(mData_deencredit.getHint_deencredit());

        clickView_deencredit.setOnClickListener(v -> {

            HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit, mData_deencredit.getParamName_deencredit().toUpperCase()+"_CLICK","");

            new AddressSelectDialog_Tanzan_deencredit(mView_deencredit.getContext(), inputTv_deencredit, addressStrs -> {

                StringBuilder value = new StringBuilder();
                for (String address:addressStrs){
                    value.append(address);
                }

                HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit, mData_deencredit.getParamName_deencredit().toUpperCase()+"_CLICK", getInput_deencredit());

                if (addressStrs.length<2) return;
                state_deencredit = addressStrs[0];
                city_deencredit = addressStrs[1];
            }, page_deencredit +"_"+ mData_deencredit.getParamName_deencredit()).show();
        });

    }

    @Override
    public boolean checkInput_deencredit() {
        if (!mData_deencredit.isMustInput_deencredit()) return true;
        return (!TextUtils.isEmpty(state_deencredit))&&(!TextUtils.isEmpty(city_deencredit));
    }

    @Override
    public String getInput_deencredit() {
        String input = inputTv_deencredit.getText().toString();
        if (TextUtils.isEmpty(input)) return "";
        return input;
    }

    public void setTitle_deencredit(String title){
        if (TextUtils.isEmpty(title)) titleTv_deencredit.setVisibility(GONE);
        else {
            titleTv_deencredit.setVisibility(VISIBLE);
            titleTv_deencredit.setText(title);
        }
    }

    public String getState_deencredit() {
        if (TextUtils.isEmpty(state_deencredit)) return "";
        return state_deencredit;
    }

    public String getCity_deencredit() {
        if (TextUtils.isEmpty(city_deencredit)) return "";
        return city_deencredit;
    }

}
